package com.dime.physical.controller;

import com.dime.physical.model.OccupationalCheckMainVO;
import com.dime.physical.model.OccupationalMainVO;
import com.dime.physical.model.dto.OccupationHealthCheckEmployeesDto;
import com.dime.physical.model.dto.SearchEmployeeConditionDto;
import com.dime.physical.model.mrreport.V_ReportVO;
import com.dime.physical.service.IDimePhysicalOccupationalService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import com.google.gson.Gson;
import com.google.gson.stream.JsonWriter;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

@RestController
@RequestMapping("/physicaloccupational")
public class DimePhysicalOccupationalController  extends BaseController {

    @Autowired
    private IDimePhysicalOccupationalService dimePhysicalOccupationalService;

    /**
     *  根据受检单位名称、时间、在岗状态查询受检人相关信息
     * @param searchCondition
     * @return
     */
    @RequiresPermissions("physical:physicaloccupational:occupationalhealthcheck")
    @PostMapping("/searchemployees")
    public TableDataInfo searchemployees(@RequestBody SearchEmployeeConditionDto searchCondition)
    {
        startPage();
        List<OccupationalCheckMainVO> list = dimePhysicalOccupationalService.searchOccupationalEmployee(searchCondition);
        return getDataTable(list);
    }


    /**
     *  根据受检人信息查询总结报告相关信息
     * @param searchCondition
     * @return
     */
    @RequiresPermissions("physical:physicaloccupational:occupationalhealthcheck")
    @PostMapping("/occupationalhealthcheck")
    public OccupationalMainVO occupationalHealthCheck(@RequestBody OccupationHealthCheckEmployeesDto searchCondition)
    {
            OccupationalMainVO main = dimePhysicalOccupationalService.occupationalHealthCheck(searchCondition);
            return main;
    }

    /**
     *  总结报告确认保存
     * @param main
     * @return
     */
    @RequiresPermissions("physical:physicaloccupational:occupationalhealthcheck")
    @PostMapping("/occupationalhealthchecksave")
    public AjaxResult occupationalHealthCheckSave(@RequestBody OccupationalMainVO main)
    {
        try {
            String r = dimePhysicalOccupationalService.occupationalHealthCheckSave(main);
            return AjaxResult.success();
        }catch (Exception ex) {
            return AjaxResult.error(ex.getMessage());
        }

    }

    /**
     * 报告审核
     * @param ids
     * @return
     */
    @RequiresPermissions("physical:physicaloccupational:occupationalhealthcheckapprove")
    @PostMapping("/occupationalhealthcheckapprove")
    public AjaxResult occupationalHealthApprove(@RequestBody String[] ids)
    {
        try {
            String r = dimePhysicalOccupationalService.occupationalHealthCheckApproveByIds(ids);
            return AjaxResult.success();
        }catch (Exception ex) {
            return AjaxResult.error(ex.getMessage());
        }
    }

    @RequiresPermissions("physical:physicaloccupational:occupationalhealthcheckbyid")
    @GetMapping("/occupationalhealthcheckbyid/{id}")
    public AjaxResult getOccupationalHealthCheck(@PathVariable("id") String id)
    {
        try {
            OccupationalMainVO main = dimePhysicalOccupationalService.getOccupationalHealthCheckById(id);
            return AjaxResult.success(main);
        }catch (Exception ex) {
            return AjaxResult.error(ex.getMessage());
        }
    }

    @RequiresPermissions("physical:physicaloccupational:occupationalhealthcheckreportinfo")
    @PostMapping("/occupationalhealthcheckreportinfo")
    public AjaxResult getOccupationalReportInfo(@RequestBody String id)
    {
        try {
            V_ReportVO vo = dimePhysicalOccupationalService.getOccupationalReportInfo(id);
            return AjaxResult.success(vo);
        }catch (Exception ex) {
            return AjaxResult.error(ex.getMessage());
        }
    }
}
